package com.kye.express.business.limit_time_query;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextPaint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kye.express.R;
import com.kye.express.databinding.ItemLimitTimeQueryBinding;
import com.kye.model.bean.limit_time_query.ResultFindServiceAging;

class LimitTimeQueryItemViewBinder extends me.drakeet.multitype.ItemViewBinder<ResultFindServiceAging.DatasBean, LimitTimeQueryItemViewBinder.ViewHolder> {

    private Context mContext;

    public LimitTimeQueryItemViewBinder(Context context) {
        mContext = context;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_limit_time_query, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull ResultFindServiceAging.DatasBean item) {
        holder.bindData(item);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private ResultFindServiceAging.DatasBean data;
        ItemLimitTimeQueryBinding dataBinding;

        public ViewHolder(View itemView) {
            super(itemView);
            dataBinding = DataBindingUtil.bind(itemView);
        }


        public void bindData(ResultFindServiceAging.DatasBean item) {
            data = item;
            if (data != null) {
                dataBinding.setDatas(data);
                if (data.isTitle()) {
                    TextPaint tp = dataBinding.tvTitle.getPaint();
                    tp.setFakeBoldText(true);
                    TextPaint tp2 = dataBinding.tvTime.getPaint();
                    tp2.setFakeBoldText(true);
                    dataBinding.tvTime.setText(data.getSendAging());
                } else if (data.isBottom()) {
                    dataBinding.tvTime.setText(data.getSendAging());
                    dataBinding.getRoot().setBackgroundColor(mContext.getResources().getColor(R.color.window_background));
                } else {
                    dataBinding.tvTime.setText(data.getSendAging() + mContext.getResources().getString(R.string.limittime_time_suffix));
                }
            }
        }
    }
}
